package com.guxingke.typecho4j.widget.handle.meta;

import com.guxingke.typecho4j.Typecho4jException;
import com.guxingke.typecho4j.jfinal.model.Meta;
import com.guxingke.typecho4j.route.DispatcherStrategy;
import com.guxingke.typecho4j.route.Route;
import com.guxingke.typecho4j.route.Routes;
import com.guxingke.typecho4j.widget.WidgetHandle;
import com.guxingke.typecho4j.widget.provider.MetaBaseWidget;
import com.guxingke.typecho4j.widget.provider.ProviderWidget;
import com.guxingke.typecho4j.widget.provider.meta.tagsManageWidget;
import com.jfinal.core.Controller;

public class TagEditHandleWidget extends MetaBaseWidget implements WidgetHandle {

	@Override
	public void configRoute(Routes routes) {
		routes.addRoute(new Route("tagEdit", this.getClass(),
				"/admin/manage-tags",
				DispatcherStrategy.REDIRECT));
	}

	@Override
	public void handle(Controller controller) throws Typecho4jException {
		Meta tag = controller.getModel(Meta.class, "tag");

		if (tag.getLong("mid") != null) {
			tag.update();
		} else {
			tag.save();
		}

		ProviderWidget.refreshProviderWidget(tagsManageWidget.class);
	}

}
